"use strict";

var wechat = require('wechat');

module.exports = function (webModule, route, options, cb) {
    options = options || {};

    var _wcpool = {}; // Wechat middlewares

    if (!options.token) {
        return cb('"token" is required!');
    }

    if (options.token in _wcpool) {
        return cb(null, _wcpool[options.token]);
    }

    var middleware = _wcpool[options.token] = wechat(options.token).middlewarify();
    cb(null, middleware);
};

